<script type="text/javascript" src="scripts/data.js"></script><?php
include('includes/dbConnection.php');
include('includes/functions.php');
$presId='1'; // current presentation
$sqlQuery=mysql_query("SELECT * FROM presentations where presId=$presId") or die(mysql_error());
$rs=mysql_fetch_assoc($sqlQuery);

//while ($rs=mysql_fetch_assoc($sqlQuery)) {
                         
$presId=$rs['presId'];
$presTitle= $rs['presTitle'];
$slideNum=$rs['slideNum'];
//echo 'slidenum' .$slideNum;// $rs['slideNum'];//$slidenum;


$slideCaptions[$slideNum+1];

copy_directory('files','slides/');

/*

mkdir("slides/files",0777);
mkdir("slides/scripts",0777);
mkdir("slides/library",0777);
*/
//copy_directory('files','slides/');

/*
exec('rm -r slides/*');
exec('mkdir -p slides/files');
exec('cp -r library slides/');
exec('cp -r library slides/');
exec('cp -r images slides/');
exec('cp -r scripts slides/');

*/






/* Caption of each  slide into JS */
$variablesJSstr="var lastSlideId=$slideNum;\n";
$variablesJSstr.="var slideCaption = new Array();\n";
$variablesJSstr.="var slideContent = new Array();\n";
$variablesJSstr.="slideCaption[0]=\"\";\n";

for($i=1;$i<=$slideNum;$i++){

$sqlQuery=mysql_query("SELECT * FROM slides where presId=$presId and slideId=$i ") or die(mysql_error());
$rs=mysql_fetch_assoc($sqlQuery);
$slideCaptions[$i]=$rs['caption'];
$slideContent[$i]=$rs['content'];
$variablesJSstr.="slideContent['$i']='$slideContent[$i]';\n";
$variablesJSstr.="slideCaption[$i]=\"$slideCaptions[$i]\";\n";

}
//echo " $slideCaptions[$i] \n";
writeInfile('slides/scripts/variables.js',$variablesJSstr);






$bpNum= $_GET["bpNum"]; //fromdatabase
$bpNum=5;
//require('templates/index_head.tpl');
//$slideNum = 5; //from db
$pagestr="";
for($i=1;$i<=$slideNum;$i++){
//echo $i."AAAAAAAAA";
	echo $slideCaptions[$i];
	$pagestr.="<script>setCaption(".$slideCaption[$i].");</script>";

	$pagestr.="<div id=$i  onclick='nextSlide(this);return false;'";
	if($i==1)
		$pagestr.= "class=slides style='display:block;' >";	
	else
		$pagestr.= "class=slides style='display:none;' >";	

	$pagestr.= "slide #" .$i. " with ".$bpNum." bullet points<br>";
	$pagestr.= $slideContent[$i];
	
	/*if($bpNum>0){
	$pagestr.= "<ul>";
	for($j=1;$j<=$bpNum;$j++){
	echo $i;
	$pagestr.= " <li id='li_$j' style='font-size:large;'>Bullet point $j asd asdasa iasd lumpus odila koneba hudu</li> "; }		
	$pagestr.= "</ul>";}
	}//bpNum*/

$pagestr.= "</div>";

}
//echo $pagestr;
//include('templates/index_footer.tpl');
//$string= $_GET["str"]; //string from generate 
//echo $pagestr;
//require('generate.php?bpNum=7');
//exec('rm -r slides');
//exec('mkdir -p slides/files');
//exec('cp -r library slides');
//exec('cp -r library slides');
//exec('cp -r images slides/');
//exec('cp -r scripts slides');




//exec('cat templates/index_head.tpl > slides/index.html');
$myFile = "slides/index.html";
$fh = fopen($myFile, 'w');
fwrite($fh, $pagestr);
fclose($fh);
/*exec('cat slides/slides.html >> slides/index.html');
exec('cat templates/index_footer.tpl >> slides/index.html');
exec('tar -cvf slides/slides.tar slides/');
*/
//echo exec('ls -l slides/') . "\n";
?>

<a href="slides/slides.tar">Download Slides as tar ball</a>
<script>Javascript.resizeTo(screen.width,screen.height); function openSlides(){ var win = window.open('slides/index.html', 'Name', 'fullscreen=true');}</script>
<a href="#"  onclick="openSlides();"> See Slides</a>
